package com.egao.appo.controller;

import com.egao.appo.entity.Appointments;
import com.egao.appo.entity.Message;
import com.egao.appo.service.AppointmentsService;
import com.egao.common.core.annotation.ApiPageParam;
import com.egao.common.core.annotation.OperLog;
import com.egao.common.core.damon.results.PageResult2;
import com.egao.common.core.utils.FileServerUtil;
import com.egao.common.core.web.BaseController;
import com.egao.common.core.web.JsonResult;
import com.egao.common.system.entity.User;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.poi.ss.formula.functions.T;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.File;


/**
 * 用户资料
 *
 * @author : Doman
 * @version ：1.0
 * @date : 2021-07-20 09:09:53
 */

@Api(tags = "用户资料")
@RestController
@RequestMapping("/api/nt/appo/appointments")
public class AppointmentsNtController extends BaseController {

    @Autowired
    private AppointmentsService appointmentsService;

    /**
     * 分页查询列表
     */
    @ApiOperation(value = "分页查询用户资料", notes = "" +
            "limit:每页显示几行 必填\n" +
            "page:第几页 必填\n" +
            " \n\n\n" +
            "返回的结果:\n" +
            "id:id\n" +
            "name:昵称\n" +
            "bCode:编号\n" +
            "pinyin:昵称拼音\n" +
            "gender:性别\n" +
            "phone:手机\n" +
            "idCardPic:身份证图片正面\n" +
            "idCardPicB:身份证图片背面\n" +
            "height:身高\n" +
            "weight:体重\n" +
            "education:学历\n" +
            "occupation:职业\n" +
            "salary:年薪\n" +
            "house:房子\n" +
            "car:车子\n" +
            "selfSituation:自身情况\n" +
            "hobby:爱好\n" +
            "requirements:择偶要求\n" +
            "birthday:生日\n" +
            "marriage:婚姻\n" +
            "nativePlace:籍贯\n" +
            "liveCity:居住\n" +
            "nativePlaceV:籍贯值\n" +
            "liveCityV:居住值\n" +
            "wechatCode:微信\n" +
            "idCard:身份证\n" +
            "educationPic:学历照片\n" +
            "photo:个人照片\n" +
            "photoPrivacy:个人照片_隐藏\n" +
            "examined: 审核状态: 未审核,未通过,已审核\n" +
            "orderNum:排序\n" +
            "createTime:创建时间\n" +
            "createUser:创建人\n" +
            "updateTime:更新时间\n" +
            "updateUser:更新人\n" +
            "", httpMethod = "GET")
    @ApiPageParam
    @GetMapping("/list2")
    public JsonResult list2(PageResult2<T> page, Appointments appointments) throws Exception {
        return appointmentsService.list2(page, appointments, new User(1));
    }

    /**
     * 分页查询列表
     */
    @ApiOperation(value = "分页查询用户资料", notes = "" +
            "limit:每页显示几行 必填\n" +
            "page:第几页 必填\n" +
            " \n\n\n" +
            "返回的结果:\n" +
            "id:id\n" +
            "name:昵称\n" +
            "bCode:编号\n" +
            "pinyin:昵称拼音\n" +
            "gender:性别\n" +
            "phone:手机\n" +
            "idCardPic:身份证图片正面\n" +
            "idCardPicB:身份证图片背面\n" +
            "height:身高\n" +
            "weight:体重\n" +
            "education:学历\n" +
            "occupation:职业\n" +
            "salary:年薪\n" +
            "house:房子\n" +
            "car:车子\n" +
            "selfSituation:自身情况\n" +
            "hobby:爱好\n" +
            "requirements:择偶要求\n" +
            "birthday:生日\n" +
            "marriage:婚姻\n" +
            "nativePlace:籍贯\n" +
            "liveCity:居住\n" +
            "nativePlaceV:籍贯值\n" +
            "liveCityV:居住值\n" +
            "wechatCode:微信\n" +
            "idCard:身份证\n" +
            "educationPic:学历照片\n" +
            "photo:个人照片\n" +
            "photoPrivacy:个人照片_隐藏\n" +
            "examined: 审核状态: 未审核,未通过,已审核\n" +
            "orderNum:排序\n" +
            "createTime:创建时间\n" +
            "createUser:创建人\n" +
            "updateTime:更新时间\n" +
            "updateUser:更新人\n" +
            "", httpMethod = "GET")
    @ApiPageParam
    @GetMapping("/carousel")
    public JsonResult carousel(PageResult2<T> page, Appointments appointments) throws Exception {
        return appointmentsService.carousel(page, appointments, new User(1));
    }

    /**
     * 随机查询一条
     */
    @ApiOperation(value = "分页查询用户资料", notes = "" +
            "limit:每页显示几行 必填\n" +
            "page:第几页 必填\n" +
            " \n\n\n" +
            "返回的结果:\n" +
            "id:id\n" +
            "name:昵称\n" +
            "bCode:编号\n" +
            "pinyin:昵称拼音\n" +
            "gender:性别\n" +
            "phone:手机\n" +
            "idCardPic:身份证图片正面\n" +
            "idCardPicB:身份证图片背面\n" +
            "height:身高\n" +
            "weight:体重\n" +
            "education:学历\n" +
            "occupation:职业\n" +
            "salary:年薪\n" +
            "house:房子\n" +
            "car:车子\n" +
            "selfSituation:自身情况\n" +
            "hobby:爱好\n" +
            "requirements:择偶要求\n" +
            "birthday:生日\n" +
            "marriage:婚姻\n" +
            "nativePlace:籍贯\n" +
            "liveCity:居住\n" +
            "nativePlaceV:籍贯值\n" +
            "liveCityV:居住值\n" +
            "wechatCode:微信\n" +
            "idCard:身份证\n" +
            "educationPic:学历照片\n" +
            "photo:个人照片\n" +
            "photoPrivacy:个人照片_隐藏\n" +
            "examined: 审核状态: 未审核,未通过,已审核\n" +
            "orderNum:排序\n" +
            "createTime:创建时间\n" +
            "createUser:创建人\n" +
            "updateTime:更新时间\n" +
            "updateUser:更新人\n" +
            "", httpMethod = "GET")
    @ApiPageParam
    @PostMapping("/randomInfo")
    public JsonResult randomInfo(PageResult2<T> page, Appointments appointments) throws Exception {
        return appointmentsService.randomInfo();
    }

    /**
     * 随机查询一条
     */
    @ApiOperation(value = "分页查询用户资料", notes = "" +
            "limit:每页显示几行 必填\n" +
            "page:第几页 必填\n" +
            " \n\n\n" +
            "返回的结果:\n" +
            "id:id\n" +
            "name:昵称\n" +
            "bCode:编号\n" +
            "pinyin:昵称拼音\n" +
            "gender:性别\n" +
            "phone:手机\n" +
            "idCardPic:身份证图片正面\n" +
            "idCardPicB:身份证图片背面\n" +
            "height:身高\n" +
            "weight:体重\n" +
            "education:学历\n" +
            "occupation:职业\n" +
            "salary:年薪\n" +
            "house:房子\n" +
            "car:车子\n" +
            "selfSituation:自身情况\n" +
            "hobby:爱好\n" +
            "requirements:择偶要求\n" +
            "birthday:生日\n" +
            "marriage:婚姻\n" +
            "nativePlace:籍贯\n" +
            "liveCity:居住\n" +
            "nativePlaceV:籍贯值\n" +
            "liveCityV:居住值\n" +
            "wechatCode:微信\n" +
            "idCard:身份证\n" +
            "educationPic:学历照片\n" +
            "photo:个人照片\n" +
            "photoPrivacy:个人照片_隐藏\n" +
            "examined: 审核状态: 未审核,未通过,已审核\n" +
            "orderNum:排序\n" +
            "createTime:创建时间\n" +
            "createUser:创建人\n" +
            "updateTime:更新时间\n" +
            "updateUser:更新人\n" +
            "", httpMethod = "GET")
    @ApiPageParam
    @PostMapping("/infoByCode")
    public JsonResult infoByCode(String code) throws Exception {
        return appointmentsService.infoByCode(code);
    }

    /**
     * 查询全部用户资料
     */
    //@OperLog(value = "用户资料", desc = "查询全部")
    @ApiOperation("查询全部用户资料")
    @GetMapping()
    public JsonResult list(Appointments appointments) {
        return appointmentsService.list(appointments, new User(1));
    }

    /**
     * 根据id查询用户资料
     */
    //@OperLog(value = "用户资料", desc = "根据id查询")
    @ApiOperation("根据id查询用户资料")
    @GetMapping("/get")
    public JsonResult get(Appointments appointments) {
        return appointmentsService.getById(appointments);
        // 使用关联查询
        //PageParam<appointments> pageParam = new PageParam<>();
        //pageParam.put("id", id);
        //List<appointments> records = appointmentsService.listAll(pageParam.getNoPageParam());
        //return JsonResult.ok().setData(pageParam.getOne(records));
    }

    @ApiOperation("预览原文件")
    @GetMapping("/{dir}/{name:.+}")
    public void preview(@PathVariable("dir") String dir, @PathVariable("name") String name,
                        HttpServletResponse response, HttpServletRequest request) {
        FileServerUtil.preview(new File(getUploadDir(), dir + "/" + name), getPdfOutDir(), openOfficeHome, response, request);
    }


    @Value("${config.upload-location:0}")
    private Integer uploadLocation;  // 文件上传磁盘位置
    @Value("${config.upload-uuid-name:false}")
    private Boolean uploadUuidName;  // 文件上传是否使用uuid命名
    @Value("${config.thumbnail-size:60}")
    private Integer thumbnailSize;  // 生成缩略图的大小
    @Value("${config.open-office-home:}")
    private String openOfficeHome;  // OpenOffice的安装目录

    /* 文件存放位置 */
    private String getBaseDir() {
        return File.listRoots()[uploadLocation] + "/damonAppGzh/upload/";
    }

    /* 文件上传目录位置 */
    private String getUploadDir() {
        return getBaseDir() + "file/";
    }

    public static String UPLOAD_DIR = File.listRoots()[0] + "/damonAppGzh/upload/file/";

    /* 缩略图存放位置 */
    private String getUploadSmDir() {
        return getBaseDir() + "thumbnail/";
    }

    /* office预览生成pdf缓存位置 */
    private String getPdfOutDir() {
        return getBaseDir() + "pdf/";
    }

}
